<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>模板语法</title>
    </head>
    <body>
        <view id="root">{{name}}</view>
        <script>
            new init({
                el: '#root',
                data: {
                    name: 'fddm',
                    age:28
                },
            });
            function init(opt) {
                this.data=opt.data
                this.el=document.querySelector(opt.el)
                this.el.innerHTML=this.el.innerHTML.replace(/\{\{(.*?)\}\}/g,(a,b)=>{
                  return  new Function(
                     ...Object.keys(this.data),
                     `return ${b}` 
                    )(...Object.values(this.data))
                
                })
            }
        </script>
    </body>
</html>
